package com.jhd.jiangxi.activity.main;

import android.os.AsyncTask;
import android.os.Bundle;

import androidx.appcompat.app.AppCompatActivity;

import com.jhd.jiangxi.barcode.Barcode2D;
import com.jhd.jiangxi.barcode.IBarcodeResult;
import com.jhd.jiangxi.barcode.NLScan;

public class ScanApi extends AppCompatActivity implements IBarcodeResult {
    Barcode2D barcode2D = null;
    NLScan nldScan=null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        setContentView(R.layout.activity_main);
        //initScan();
//        barcode2D.startScan(this);
    }

    protected void initScan() {
        //barcode2D = new Barcode2D();
        nldScan=new NLScan();
        new InitTask().execute();// open();
    }

    @Override
    protected void onDestroy() {
        ////closeNLDScan();
        super.onDestroy();
//        Process.killProcess(Process.myPid());
    }

    @Override
    public void getBarcode(String barcode) {
//        tvData.setText(barcode);
    }


    public class InitTask extends AsyncTask<String, Integer, Boolean> {
        //        ProgressDialog mypDialog;
        @Override
        protected Boolean doInBackground(String... params) {
            // TODO Auto-generated method stub
            ////openNLDScan();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return true;
        }

        @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
//            if(mypDialog.isShowing())mypDialog.dismiss();
        }

        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
//            mypDialog = new ProgressDialog(ScanApi.this);
//            mypDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
//            mypDialog.setMessage("扫码初始化...");
//            mypDialog.setCanceledOnTouchOutside(false);
//            mypDialog.setCancelable(false);
//            mypDialog.show();
        }

    }



    /*protected void stopScan() {
        barcode2D.stopScan(this);
    }

    public void //openNLDScan() {
        if (barcode2D == null) return;
        barcode2D.open(this, this);
    }

    public void //closeNLDScan() {
        if (barcode2D == null) return;
        barcode2D.stopScan(this);
        barcode2D.close(this);
    }*/


}
